package com.cch.cooperation.api.common.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.cch.cooperation.api.common.properties.OpenAiProperties;
import com.cch.cooperation.api.common.properties.SmsProperties;
import com.cch.cooperation.api.common.sdk.openai.OpenAiClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 阿里云配置
 *
 * @author cch
 */
@Configuration
public class AliConfiguration {

    @Resource
    SmsProperties smsProperties;
    @Resource
    private OpenAiProperties openAiProperties;

    @Bean
    public IAcsClient acsClient() {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", smsProperties.getAccessKeyID(), smsProperties.getAccessKeySecret());
        return new DefaultAcsClient(profile);
    }

    @Bean
    public OpenAiClient openAiClient() {
        return new OpenAiClient("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", openAiProperties.getApiKey());
    }

}
